﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace HY.BLL.oa
{
  public  class ad
    {


      public static DataTable get_list(string ty)
        {
            string sqltxt = "select * from hr_ad where adtype='"+ty+"' ";

            sqltxt = sqltxt + " order by sid desc ";
            DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
            return dt;
        }

      public static DataTable get_list_top(string ty)
      {
          string sqltxt = "select top 20 * from hr_ad where adtype='" + ty + "' ";

          sqltxt = sqltxt + " order by sid desc ";
          DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
          return dt;
      }

        public static DataTable get_list(string where,string ty)
        {
            string sqltxt = "select * from hr_ad where adtype='"+ty+"'  ";
            if (where != "") sqltxt = sqltxt + " and " + where;

            sqltxt = sqltxt + " order by sid desc ";
            DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
            return dt;
        }


        public static DataTable get_list_wk(string ty, string us)
        {
            string sqltxt = "select * from hr_ad where adperson='" + us + "' and adtype='" + ty + "' ";

            sqltxt = sqltxt + " order by sid desc ";
            DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
            return dt;
        }


        public static DataTable get_list_wk(string where, string ty,string us)
        {
            string sqltxt = "select * from hr_ad where adperson='" + us + "' and adtype='" + ty + "'  ";
            if (where != "") sqltxt = sqltxt + " and " + where;

            sqltxt = sqltxt + " order by sid desc ";
            DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
            return dt;
        }

        public static DataTable get_view(string where)
        {
            string sqltxt = "select * from hr_ad where 1=1  ";
            if (where != "") sqltxt = sqltxt + " and " + where;

            sqltxt = sqltxt + " order by sid desc ";
            DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
            return dt;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static int DeleteList(string sidlist)
        {
            string sqltxt = "delete hr_ad where sid in("+sidlist+") ";
            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
       }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static int insert(string titel,string person, string day,string memo,string adfile, string stype)
        {
            string sqltxt = "insert into  hr_ad values(getdate(),N'" +
                person + "',N'" + 
                titel + "',N'" + 
                memo + "'," +
                day + ",N'" +
                 adfile + "',N'"+stype+"','') ";

            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static int insert(string titel, string person, string day, string memo, string adfile, string stype,string subtype)
        {
            string sqltxt = "insert into  hr_ad values(getdate(),N'" +
                person + "',N'" +
                titel + "',N'" +
                memo + "'," +
                day + ",N'" +
                 adfile + "',N'" + stype + "',N'" + subtype + "') ";

            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static int update_ad(string sid,string titel,string day, string memo, string adfile)
        {

            string sqltxt ="";
            if(adfile!="")
               sqltxt= "update  hr_ad  set adtitle=N'" + titel +
                "',adcontents=N'"+memo+
                "',adday="+day+
                ",adfile=N'"+adfile+"' "+
                " where sid="+sid;
            else
                   sqltxt= "update  hr_ad  set adtitle=N'" + titel +
                "',adcontents=N'"+memo+
                "',adday="+day+" "+
                " where sid="+sid;
      

            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static int update_ad(string sid, string titel, string day, string memo, string adfile,string subtype)
        {

            string sqltxt = "";
            if (adfile != "")
                sqltxt = "update  hr_ad  set adtitle=N'" + titel +
                 "',adcontents=N'" + memo +
                 "',adday=" + day +
                 ",adfile=N'" + adfile + "' " +
                 ",adsubtype=N'" + subtype + "' " +
                 " where sid=" + sid;
            else
                sqltxt = "update  hr_ad  set adtitle=N'" + titel +
             "',adcontents=N'" + memo +
             "',adday=" + day + " " +
              ",adsubtype=N'" + subtype + "' " +
             " where sid=" + sid;


            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
        }


    }
}
